20. Three-Dimensional Data
Three-Dimensional Data
Three-Dimensional Data
Now that you've worked with one-dimensional and two-dimensional data, you might be wondering how to work with three or more dimensions.
3D data in NumPy
NumPy arrays can have arbitrarily many dimensions. Just like you can create a 1D array from a list, and a 2D array from a list of lists, you can create a 3D array from a list of lists of lists, and so on. For example, the following code would create a 3D array:
a = np.array([
[['A1a', 'A1b', 'A1c'], ['A2a', 'A2b', 'A2c']],
[['B1a', 'B1b', 'B1c'], ['B2a', 'B2b', 'B2c']]
])
3D data in Pandas
Pandas has a data structure called a Panel, which is similar to a DataFrame or a Series, but for 3D data. If you would like, you can learn more about Panels here.